<?php

//  Only errors
error_reporting(E_ERROR | E_PARSE);
//error_reporting(E_ALL);
// Debug constant
define("DEBUG_SCRIPT", "1");
define("DEBUG_SIMULATE", "0");

// Main class functions for sorter
require "functions/sort_main.php";
// Torrent class
require "functions/torrent.php";
// Database class
require "functions/db.php";
// Config class
require "functions/config.php";
// Subtitle class
require "functions/subtitle.php";
// Upgrade class
require "functions/upgrade.php";
// Log class
require "functions/log.php";

// Instance and get config
$config_class = new config;
$config = $config_class->load_config();
$db = $config_class->get_db();

if ($config["Debug"]["level"] == 3) {
    print "PHP info:\n";
    print "PHP version:" . phpversion() . "\n";
    foreach (get_loaded_extensions() as $i => $ext) {
        $ver = phpversion($ext);
        if ($ver)
            print $ext . " => " . $ver . "\n";
    }
    sleep(2);
    die();
}

// Instance log
$log = new log($config, $db);

// Extract version and format it
$verrows = $db->get_rows("version");
foreach ($verrows as $verrow) {     // make version string
    $ver[$verrow['name']]['major'] = $verrow['major'];
    $ver[$verrow['name']]['minor'] = $verrow['minor'];
}

// Instance classes
$subtitle = new subtitle($config, $log);
$upgrade = new upgrade;
$sort_main = new sort_main($config, $db, $log);
$torrent = new torrent($config, $db, $sort_main);
?>
